<?php
class Admin_Model_Menu2{

	private $menuTbl;
	
	public function __construct(){
		$this->menuTbl = new Admin_Model_DbTable_Menu2();
	}
	
	public function selectMenu2($where=NULL,$order = NULL){
		$dbAdapter = Zend_Db_Table::getDefaultAdapter();
		$dbSelect = new Zend_Db_Select($dbAdapter);
		
		$dbSelect->from(array('mn2'=>'menu2'),"*")
				->joinLeft(array('mn1'=>'menu1'), "mn1.menu1Id = mn2.menu1Id");
		
		if ($where!=NULL) {
			$dbSelect->where($where);			
		}
		if ($order!=null) {
			$dbSelect->order($order);
		}
		
		return $dbSelect;
	}
	
	public function addMenu2($tenMenu2, $menu1Id, $dichVu){
		$data = array(
			'tenMenu2'	=> $tenMenu2,
			'menu1Id'	=> $menu1Id,
			'dangKyDV'	=> $dichVu
		);
		
		$this->menuTbl->insert($data);
	}
	
	public function addCustomMenu2($data){
		$this->menuTbl->insert($data);
	}
	
	public function updateMenu2($tenMenu2, $menu1Id,$dichVu, $menu2Id){
		$data = array(
			'tenMenu2'	=> $tenMenu2,
			'menu1Id'	=> $menu1Id,
			'dangKyDV'	=> $dichVu
		);
		
		$this->menuTbl->update($data, 'menu2Id = '.$menu2Id);
	}
	
	public function updateCustomMenu2($data,$where){
		$this->menuTbl->update($data, $where);
	}
	
	public function deleteMenu2($menu2Id){
		$this->menuTbl->delete("menu2Id = ".$menu2Id);
	}
	
	public function fetchRowMenu2($menu2Id){
		return $this->menuTbl->fetchRow("menu2Id = ".$menu2Id);
	}
	
	public function fetchAllMenu2($where=NULL){
		if($where!=NULL){
			return $this->menuTbl->fetchAll($where);	
		}else {
			return $this->menuTbl->fetchAll();	
		}
	}
	
	public function fetchColMenu2($arrCol,$where=NULL){
		$sql= "SELECT ";
		for ($i =0; $i <count($arrCol);$i++){
			if($i != count($arrCol)-1)
				$sql .= " ".$arrCol[$i].",";
			else 
				$sql .= " ".$arrCol[$i];
		}
		
		$sql .= " FROM Menu2 ";
		if($where!=NULL){
			$sql .= " WHERE ".$where;
		}
		
		return $this->menuTbl->getDefaultAdapter()->fetchAll($sql);
	}
}

